<!DOCTYPE HTML>
<html>
<head>
<include file="Include:meta" />
<title>商务签约-目的地运营集团数据管理平台</title>
<include file="Include:style" />
</head>
<body>
<include file="Include:header" />
<include file="Include:left" />
<div id="main">
	<div class="crumbs">
		<div class="crumbs-text"><if condition="$project['info_id'] neq NULL">商务跟进</if>项目 > [{$project['project_num']}]{$project['project_name']} > 商务签约</div>
	</div>
	<div id="content">
		<include file="Include:project_header" />
		<form method="post" name="number_validate" id="password_validate" novalidate="novalidate">
			<div class="form-main" style="margin-bottom: 0; border-bottom: 0">
				<div class="form-title">商务签约</div>
				<div class="form-item">
					<div class="input-label">客户</div>
					<div class="input-item">
						<if condition="$customer neq NULL">
							<foreach name="customer" item="vo">
								<span class="mr20">
									<a href="javascript:;" class="detail" mid="{$vo['id']}">{$vo['username']}<if condition="$vo['company_name'] neq NULL">【{$vo['company_name']}】</if></a>
								</span>
							</foreach>
						<else/>
							暂无相关客户(客户来源于项目启动表)
						</if>
					</div>
				</div>
			</div>
			<div class="form-main">
				<if condition="$project['qy_status'] eq NULL">
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>框架协议</div>
					<div class="input-item">
						<label class="radio-inline middle mr10 have"><input type="radio" name="is_contract" value="1" <if condition="$project['is_contract'] eq 1">checked</if>>有</label>
						<span class="clearboth middle mr20 hide" <if condition="$project['is_contract'] eq 1">style="display: inline-block"</if>>
							<div class="input-group w250 left">
								<input type="text" name="file_contract_name" class="form-control file-name" value="{$project['file_contract_name']}" placeholder="请上传附件" <if condition="$project['file_contract_url'] eq NULL">readonly</if> autocomplete="off">
								<span class="input-group-btn">
									<button class="btn file-submit" type="button">上传</button>
								</span>
							</div>
							<button <if condition="$project['file_contract_url'] neq NULL">class="btn file-delete ml5"<else/>class="btn file-delete ml5 hide"</if> type="button">删除</button>
							<input type="hidden" name="file_contract_url" value="{$project['file_contract_url']}" class="file-url" autocomplete="off">
							<span class="error-item">文件名必填</span>
						</span>
						<label class="radio-inline middle none"><input class="none_inp" type="radio" name="is_contract" value="-1" <if condition="$project['is_contract'] eq -1">checked</if>>无</label>
						<span class="error-item">必填项</span>
					</div>
				</div>
				<else />
				<div class="form-item">
					<div class="input-label">框架协议</div>
					<div class="input-item">
						<if condition="$project['is_contract'] eq 1"><if condition="$project['file_contract_url'] neq NULL">{$project['file_contract_name']}<a href="{$project['file_contract_url']}" target="_blank" class="ml5" data-toggle="tooltip" data-placement="right" title="下载"><i class="glyphicon glyphicon-download-alt"></i></a></if><else />无</if>
					</div>
				</div>
				</if>
				<if condition="$project['qy_status'] eq 1">
					<div class="editor_cont" style="border-bottom: 1px solid #e5e5e5;">
						<div class="form-item">
							<div class="input-label"><span class="asterisk">*</span>正式协议上传</div>
							<div class="input-item">
									<div class="input-group w250 left mr10">
										<input type="text" name="file_formal_name[]" class="form-control file-name" placeholder="请上传相关文档" readonly autocomplete="off">
										<span class="input-group-btn">
											<button class="btn file-submit" type="button">上传</button>
										</span>
									</div>
									<input type="hidden" name="file_formal_url[]" class="file-url" autocomplete="off">
									<span class="error-item">文件名必填</span>
									<a href="javascript:;" class="data-add" data-toggle="tooltip" data-placement="bottom" title="生成"><i class="glyphicon glyphicon-plus"></i></a><span class="input-prompt"><i class="glyphicon glyphicon-exclamation-sign ml10"></i> 上传以后请点击生成</span>
									<span class="error-item">请添加一个文件</span>
									<span class="error-item">请先上传此附件</span>
									<span class="error-item">文件名不能有“,”符号</span>
							</div>
						</div>
						<if condition="$project['file_formal_url'] neq NULL">
						<foreach name="project['file_formal_url']" item="vo">
							<div class="form-item">
								<div class="input-item">
									<div class="input-group w250 left mr10">
										<input type="text" name="file_formal_name[]" value="{$project['file_formal_name'][$key]}" class="form-control file-name" placeholder="请上传相关文档" autocomplete="off">
									</div>
									<input type="hidden" name="file_formal_url[]" value="{$vo}" class="file-url" autocomplete="off">
									<span class="error-item">文件名必填</span>
									<a href="javascript:;" class="data-delete mr10" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="删除"><i class="glyphicon glyphicon-trash"></i></a>
									<span class="error-item">请添加一个文件</span>
									<span class="error-item">请先上传此附件</span>
									<span class="error-item">文件名不能有“,”符号</span>
								</div>
							</div>
						</foreach>
						</if>
					</div>
					<div class="form-item">
						<div class="input-label"><span class="asterisk">*</span>所属中心</div>
						<div class="input-item">
							<select name="center_types" class="form-control select-add w300 customers" autocomplete="off">
								<option value="-10" selected>请选择</option>
								<option value="建设中心" <if condition="$project['center_types'] eq 建设中心">selected</if>>建设中心</option>
								<option value="运营中心" <if condition="$project['center_types'] eq 运营中心">selected</if>>运营中心</option>
								<option value="产品公司" <if condition="$project['center_types'] eq 产品公司">selected</if>>产品公司</option>
							</select>
							<span class="error-item">必填项</span>
						</div>
					</div>
					<div class="form-item">
						<div class="input-label"><span class="asterisk">*</span>业务类型</div>
						<div class="input-item">
							<select name="yewu_types" class="form-control select-add w300 customers" autocomplete="off">
								<option value="-10">请选择</option>
								<option value="景区类" <if condition="$project['yewu_types'] eq '景区类'">selected</if>>景区类</option>
								<option value="IP类" <if condition="$project['yewu_types'] eq 'IP类'">selected</if>>IP类</option>
								<option value="策划类" <if condition="$project['yewu_types'] eq '策划类'">selected</if>>策划类</option>
							</select>
							<span class="error-item">必填项</span>
						</div>
					</div>
					<div class="form-item">
						<div class="input-label"><span class="asterisk">*</span>是否签约</div>
						<div class="input-item">
							<span class="checkbox-item">
								<label class="checkbox-inline"><input type="checkbox" class="yes" name="is_sign" value="是" <if condition="$project['is_sign'] eq '是'">checked</if>>是</label>
								<span class="error-item">必填项</span>
							</span>
						</div>
					</div>
				<elseif condition="$project['is_sign'] neq NULL and $project['qy_status'] neq NULL" />
					<div class="form-item">
						<div class="input-label">正式协议上传</div>
						<div class="input-item">
						<foreach name="project['file_formal_url']" item="vo">
							<if condition="$vo neq NULL">{$project['file_formal_name'][$key]}<a href="{$vo}" target="_blank" class="ml5 mr15" data-toggle="tooltip" data-placement="right" title="下载"><i class="glyphicon glyphicon-download-alt"></i></a></if>
						</foreach>
						</div>
					</div>
					<div class="form-item">
						<div class="input-label">所属中心</div>
						<div class="input-item">
						{$project['center_types']}
						</div>
					</div>
					<div class="form-item">
						<div class="input-label">业务类型</div>
						<div class="input-item">
						{$project['yewu_types']}
						</div>
					</div>
					<div class="form-item">
						<div class="input-label">是否签约</div>
						<div class="input-item">
						{$project['is_sign']}
						</div>
					</div>
				</if>
				<if condition="$project['qy_status'] eq 2">
				<div class="form-item">
					<div class="input-label"><span class="asterisk">*</span>首款到款</div>
					<div class="input-item">
						<span class="checkbox-item">
							<label class="checkbox-inline"><input class="yes" type="checkbox" name="is_first_money" value="是">是</label>
							<span class="error-item">必填项</span>
						</span>
					</div>
				</div>
				<elseif condition="$project['is_first_money'] neq NULL" />
				<div class="form-item">
					<div class="input-label">首款到款</div>
					<div class="input-item">{$project['is_first_money']}</div>
				</div>
				</if>
				<if condition="((((get_permission($qs,NULL,3)) and ($project['add_uid'] eq $login_id)) or (get_permission($qs,NULL,2) and (in_array($project['center_id'],$manage_id))) or (get_permission($qs,NULL,1))) or ($project['director_uid'] eq $login_id) or ($project['manager_uid'] eq $login_id)) and ($project['status'] eq 1)">
					<if condition="($project['qy_status'] eq NULL or $project['qy_status'] eq 1 or $project['qy_status'] eq 2) and ($project['tp_status'] eq 1)">
						<div class="form-btn-item">
						<if condition="$project['qy_status'] eq NULL">
							<button class="btn submit submit1" action="contract_one" type="button">提交</button>
						<elseif condition="$project['qy_status'] eq 1" />
							<button <if condition="$project['is_sign'] neq '是'">class="btn submit submit2"<else />class="btn submit submit2 active"</if> action="contract_two" type="button" <if condition="$project['is_sign'] neq '是'">disabled</if>>提交</button>
							<button class="btn back" action="lost_submit_one" type="button">撤回</button>
						<else />
							<button class="btn submit submit3" action="contract_three" type="button" disabled>提交</button>
							<button class="btn back" action="lost_submit_two" type="button">撤回</button>
						</if>
						</div>
					<else />
						<div class="form-btn-item form-item">
							<button class="btn submit submit3" action="contract_three" type="button" disabled>提交</button>
								<span class="input-prompt"><i class="glyphicon glyphicon-exclamation-sign ml10"></i> 前期沟通,商务谈判阶段完成以后，方可提交</span>
						</div>
					</if>
				</if>
			</div>
		</form>
	</div>
</div>
<!--弹出框-->
<div class="modal fade" id="customeModal">
	<div class="modal-dialog w800">
		<div class="modal-content">
			<div class="modal-header">
				<h4>添加客户</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body"></div>
		</div>
	</div>
</div>
<!--客户详情-->
<div id="detailModal" class="modal hide fade">
	<div class="modal-dialog w800">
		<div class="modal-content">
			<div class="modal-header">
				<h4 id="myModalLabel">客户详情</h4>
				<i class="fa fa-times" aria-hidden="true" data-dismiss="modal"></i>
			</div>
			<div class="modal-body"></div>
		</div>
	</div>
</div>
<include file="Include:javascript" />
<script>
$(function(){
	$('.have').click(function(){
		$(this).next('span').css('display','inline-block');
		$(this).nextAll('.error-item').hide();
	})
	$('.none').click(function(){
		$(this).prev('span').hide();
		$(this).nextAll('.error-item').hide();
	})
	//客户详情
	$(".detail").on("click",function(){
		var mid = $(this).attr("mid");
		$.ajax({
			type:"POST",
			async:false,
			dataType:"json",
			data:{"id":mid},
			url:"__APP__/Project/project_card_detail",
			success:function(data){
				var html = "<table class='table table-bordered'>";
				html+="<tr><td class='side_td' width='10%'>姓名</td><td width='40%'>";
				html+=data.username ? data.username : "";
				html+="</td>";
				html+="<td class='side_td' width='10%'>性别</td><td width='40%'>";
				html+=data.gender ? data.gender : "";
				html+="</td></tr>";
				html+="<tr><td class='side_td'>公司名称</td><td>";
				html+=data.company_name ? data.company_name : "";
				html+="</td><td class='side_td'>职位</td><td>";
				html+=data.job ? data.job : "";
				html+="</td></tr>";
				html+="<tr><td class='side_td'>手机号</td><td>";
				html+=data.mobilephone ? data.mobilephone : "";
				html+="</td><td class='side_td'>座机号</td><td>";
				html+=data.telephone ? data.telephone : "";
				html+="</td></tr>";
				html+="<tr><td class='side_td'>QQ</td><td>";
				html+=data.qq ? data.qq : "";
				html+="</td><td class='side_td'>邮箱</td><td>";
				html+=data.email ? data.email : "";
				html+="</td></tr>";
				html+="<tr><td class='side_td'>地址</td><td colspan='3'>";
				if(data.province){
					html+=data.province+"-"+data.city;
					html+=data.address ? "-"+data.address : "";
				}else{
					html+=data.address ? data.address : "";
				}
				html+="</td></tr>";
				html+="<tr><td class='side_td'>其它信息</td><td colspan='3'>";
				html+=data.remark ? data.remark : "";
				html+="</td></tr>";
				html+="</table>";
				$("#detailModal").find(".modal-body").html(html).end().modal();
			}
		});
	});
	KindEditor.ready(function(K){
		//上传附件
		var editorFile = K.editor();
		$('.file-submit').on('click',function(){
			var parents = $(this).parents(".input-group");
			editorFile.loadPlugin('insertfile',function(){
				document.cookie="file_name=contract";
				document.cookie="file_type=ppt,pptx,pdf,doc,docx,jpg,jpeg,png,xls,xlsx,txt,rar,zip";
				editorFile.plugin.fileDialog({
					clickFn:function(url,title){
						parents.nextAll(".error-item").hide();
						parents.find(".file-name").val(title).prop("readonly",false);
						parents.nextAll(".file-url").val(url);
						parents.nextAll(".file-delete").show();
						editorFile.hideDialog();
						$('.have').click();
					}
				});
			});
		});
	});
	//添加资料
	$("body").on("click",".data-add",function(){
		$(this).siblings('.error-item').hide();
		var val = $(this).siblings('.input-group').find('.form-control').val();
		if((val=="" || /^\s+$/.test(val)) && !$(this).prop("readonly")){
			$(this).parent().find('.error-item').eq(2).show();
		}else{
			var tr = $(this).parents(".form-item"),
				cont = $('.editor_cont'),
				html = tr.clone(true);
			
			html.find(".tooltip,.input-group-btn").remove();
			html.find('.input-label').html('');
			tr.find(".error-item,.file-delete").hide();
			html.find(".file-delete").hide();
			tr.find(":text,:hidden").val("");
			tr.find(".file-name").prop("readonly",true);
			html.find(".data-add").replaceWith("<a href='javascript:;' class='data-delete mr10' data-toggle='tooltip' data-placement='bottom' title='删除'><i class='glyphicon glyphicon-trash'></i></a>");
			html.find(".data-delete,.data-add").tooltip({trigger:'hover'});
			cont.append(html);
		}
	});
	//删除资料
	$(document).on("click",".data-delete",function(){
		$(this).parents(".form-item").remove();
	});
	//添加联系人
	$(".add_cus").click(function(){
		var pid = "{$project['id']}",
			center_id = "{$project['center_id']}",
			arr = [];
		$("[name='hide_val[]']").each(function(){
			arr.push($(this).val());
		});
		$('#customeModal').find('.modal-body').load("__APP__/Project/project_card_add/pid/"+pid+"/way/2/since/1/center_id/"+center_id+"/arr/"+arr).end().modal('show');
	});
	//删除客户
	$(document).on('click','.pname-delete',function(){
		$(this).parents('.user-add').remove();
	})
	//删除附件
	$(".file-delete").click(function(){
		$(this).hide();
		$(this).nextAll(".error-item").hide();
		$(this).nextAll(".file-url").val("");
		$(this).prevAll(".input-group").find(".file-name").val("").prop("readonly",true);
		$(this).parents("tr").find(".required-text").next(".error-item").hide();
	});
	$(".yes").click(function(){
		if($('.submit').hasClass('active')){
			$('.submit').removeClass('active').attr('disabled',true);
		}else{
			$('.submit').addClass('active').attr('disabled',false);
		}
	})
	//提交验证
	$('.submit1').click(function(){
		var tag = true;
		if($('.file-url').val()=='' && $('.none_inp:checked').length==0){
			tag = false;
			$(this).parent().siblings().find('.error-item').eq(1).show();
		}
		if(tag){
			var action = $(this).attr("action"),
				pid = "{$project['id']}";
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:$("[name='number_validate']").serialize()+"&action="+action+"&id="+pid,
				url:"__APP__/Project/stage_ajax",
				success:function(data){
					success_pop(data.status,data.msg);
				}
			});
		}
	})
	$('.submit2').click(function(){
		var tag = true;
		if($("[name='is_sign']:checked").length==0){
			$("[name='is_sign']").parent().siblings(".error-item").show();
			tag = false;
		}
		$(".select-add").each(function(){
			if($(this).val()==-10){
				$(this).nextAll(".error-item").show();
				tag = false;
			}
		});
		$(".file-name").each(function(){
			var val = $(this).val(),
				_this = $(this)
			if((val=="" || /^\s+$/.test(val)) && !$(this).prop("readonly")){
				_this.parent(".input-group").nextAll(".error-item").eq(0).show();
				tag = false;
			}
			if(val!="" && /\,/.test(val)){
				_this.parent(".input-group").nextAll(".error-item").eq(3).show();
				tag = false;
			}
		});
		$(".file-url").each(function(){
			var val = $(this).val();
			if(val!=""){
				$(this).parents("tr").find(".required-text").each(function(){
					var val2 = $(this).val();
					if(val2=="" || /^\s+$/.test(val2)){
						$(this).next(".error-item").eq(2).show();
						tag = false;
					}
				});
			}
		});
		if($('.editor_cont .form-item').length<2){
			tag = false;
			$('.editor_cont').find('.error-item').hide().eq(1).show();
		}
		if(tag){
			var action = $(this).attr("action"),
				pid = "{$project['id']}";
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:$("[name='number_validate']").serialize()+"&action="+action+"&id="+pid,
				url:"__APP__/Project/stage_ajax",
				success:function(data){
					success_pop(data.status,data.msg);
				}
			});
		}
	})
	$('.submit3').click(function(){
		var action = $(this).attr("action"),
			pid = "{$project['id']}";
		$.ajax({
			type:"POST",
			async:false,
			dataType:"json",
			data:$("[name='number_validate']").serialize()+"&action="+action+"&id="+pid,
			url:"__APP__/Project/stage_ajax",
			success:function(data){
				success_pop(data.status,data.msg);
			}
		});
	})
	//撤回
	$('.back').click(function(){
		var action = $(this).attr("action"),
			pid = "{$project['id']}";
		$.ajax({
			type:"POST",
			async:false,
			dataType:"json",
			data:$("[name='number_validate']").serialize()+"&action="+action+"&id="+pid,
			url:"__APP__/Project/stage_ajax",
			success:function(data){
				success_pop(data.status,data.msg);
			}
		});
	})
	/*
	$(".submit").on('click',function(){
		
				
		if(tag){
			var contract_add = 'contract_add',
				pid = "{$project['id']}",
				status = 1;
			$.ajax({
				type:"POST",
				async:false,
				dataType:"json",
				data:$("[name='number_validate']").serialize()+"&action="+contract_add+"&pid="+pid+"&status="+status,
				url:"__APP__/Project/stage_ajax",
				success:function(data){
					success_pop(data.status,data.msg);
				}
			});    
		}
	});
	*/
	//隐藏错误提示
	$(".required-text").focus(function(){
		$(this).nextAll(".error-item").hide();
	});
	$("select.required-selt,select.select-add").change(function(){
		$(this).nextAll(".error-item").hide();
	});
	$("[name='type']").click(function(){
		$(this).parent().siblings(".error-item").hide();
	});
	$(".is_all_btn").click(function(){
		$(this).siblings(".error-item").hide();
	});
	$("[name='is_sign']").click(function(){
		$(this).parent().siblings(".error-item").hide();
	});
	$(".file-name").on("focus",function(){
		$(this).parents(".input-group").nextAll(".error-item").hide();
	});
})
</script>
</body>
</html>